package com.ruoyi.common.core.page;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;

/**
 * 基础数据结构定义
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResultEntity<T> {

    @ApiModelProperty("结果（true or false）")
    private Boolean success;
    @ApiModelProperty("错误编码")
    private String errorCode;
    @ApiModelProperty("错误描述")
    private String errorMsg;
    @ApiModelProperty("返回结果")
    private T data;

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static ResultEntity createSuccess() {
        ResultEntity responseEntity = new ResultEntity();
        responseEntity.setSuccess(true);
        return responseEntity;
    }

    public static <K> ResultEntity<K> createSuccess(K object) {
        ResultEntity<K> responseEntity = new ResultEntity<>();
        responseEntity.setSuccess(true);
        responseEntity.setData(object);
        return responseEntity;
    }

    public static ResultEntity createError(String code, String msg) {
        ResultEntity responseEntity = new ResultEntity();
        responseEntity.setSuccess(false);
        responseEntity.setErrorCode(code);
        responseEntity.setErrorMsg(msg);
        return responseEntity;
    }
}
